import java.io.*;
public class Test implements Serializable {
    private static final long serialVersionUID = 1L;
    public static int n = 1;
    public static void main(String[] args) {
        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(
                    new FileOutputStream("明志学编程！"));
            outputStream.writeObject(new Test());
            outputStream.close();
            //序列化后修改值
            Test.n = 2;
            ObjectInputStream objectInputStream = new ObjectInputStream(
                    new FileInputStream("明志学编程！"));
            Test t = (Test) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println(t.n);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
